<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>盘点损益表&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: 19px;">计划编号：</span><span style="font-size: 19px;"
                                                                                      th:text="${checkPlan.cpnCode}"></span>
    </h1>
    <div class="pull-right"
         style="margin:0px 5px 5px 5px;text-align: right">
        <a href="/material/checkPlan/plan" shiro:hasPermission="matinv:matcheckplan:view"
           id="btn-return-checkPlanList"
           class="btn btn-info">返回计划列表
        </a>
    </div>
    <div class="pull-right"
         style="margin:0px 5px 5px 5px;text-align: right">
        <a th:href="@{'/material/checkPlan/adjust/'+${checkPlan.cpnId}}"
           shiro:hasPermission="matinv:matcheckadj:view" id="btn-prev"
           class="btn btn-success">上一步
        </a>
    </div>
</section>
<section class="content">
    <input type="hidden" id="cpnId" name="cpnId"
           th:value="${checkPlan.cpnId}">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">

                </div>
                <div class="box-body">
                    <div class="row">
                        <div class="col-md-9">
                            <h4>选中行损益汇总</h4>
                        </div>
                        <div class="col-md-3">
                            <button shiro:hasPermission="matinv:matchecksub:edit" id="btn-updatePalStatus" class="btn btn-success pull-right"
                                    th:text="@{(${checkPlan.cpnPalStatus} == 3 ? '撤销' : '提交')}">
                            </button>
                        </div>
                    </div>
                    <table id="pal-table" class="table table-bordered " width="100%"></table>
                    <hr>
                    <h4>库存调整申请</h4>
                    <table id="bootstrap-table" class="table table-bordered " width="100%"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table1, table2;


    $(function () {

        //加载列表数据
        table1 = js.table.init({
            id: 'bootstrap-table',
            pageSize: 300,
            pagination: false,
            url: ctx + "material/checkPlan/resultCommit",
            showExport: false,
            queryData: {cpnId: $("#cpnId").val()},
            columns: [
                {
                    title: '序号', field: 'ajaId', width: '40',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '物料描述', field: 'matNameDesc'},
                {title: '项目文本', field: 'ityProCode'},
                {title: '账面在库重量', field: 'inStockWeight'},
                {
                    title: '重量损溢差', field: 'ajaWeight', cellStyle: function (value, row, index) {
                        if (row.profitLossFlg == 2) {
                            return {css: {"color": "red", "font-weight": "900"}}
                        } else if (row.profitLossFlg == 1) {
                            return {css: {"color": "green"}}
                        } else {
                            return {css: {"color": "#333333"}}
                        }
                    }
                },
                {
                    title: '损溢类型', field: 'profitLossFlg',
                    formatter: function (value, row, index) {
                        if (value == 1) {
                            return '报溢';
                        } else if (value == 2) {
                            return '报损';
                        }
                    },
                    cellStyle: function (value, row, index) {
                        if (row.profitLossFlg == 2) {
                            return {css: {"color": "red", "font-weight": "900"}}
                        } else if (row.profitLossFlg == 1) {
                            return {css: {"color": "green"}}
                        } else {
                            return {css: {"color": "#333333"}}
                        }
                    }
                },
                {title: '单价', field: 'cdlPrice'},
                {
                    title: '金额损溢差', field: 'cdlPalAmount', cellStyle: function (value, row, index) {
                        if (row.profitLossFlg == 2) {
                            return {css: {"color": "red", "font-weight": "900"}}
                        } else if (row.profitLossFlg == 1) {
                            return {css: {"color": "green"}}
                        } else {
                            return {css: {"color": "#333333"}}
                        }
                    }
                },
            ]
        });

        table2 = js.table.init({
            id: "pal-table",
            url: ctx + "material/checkPlan/resultCommitSum",
            pageSize: 300,
            showExport: false,
            pagination: false,
            queryData: {cpnId: $("#cpnId").val()},
            columns: [
                {
                    title: '盘盈数量', field: 'profitWeight', cellStyle: function (value, row, index) {
                        return {css: {"color": "green"}}
                    }
                },
                {
                    title: '盘亏数量', field: 'lossWeight', cellStyle: function (value, row, index) {
                        return {css: {"color": "red", "font-weight": "900"}}
                    }
                },
                {
                    title: '盘盈金额', field: 'profitAmount', cellStyle: function (value, row, index) {
                        return {css: {"color": "green"}}
                    }
                },
                {
                    title: '盘亏金额', field: 'lossAmount', cellStyle: function (value, row, index) {
                        return {css: {"color": "red", "font-weight": "900"}}
                    }
                },
                {
                    title: '金额差值', field: 'differenceValueAmount', cellStyle: function (value, row, index) {
                        if (value >= 0) {
                            return {css: {"color": "green"}}
                        } else {
                            return {css: {"color": "red", "font-weight": "900"}}
                        }
                    }
                },
            ]
        });

        /** 更新盘点状态 */
        $("#btn-updatePalStatus").click(function () {
            var msg;
            if ($("#cpnResStatus").val() == 3) {
                msg = "确定撤销盘点结果吗？撤销后，本次盘点损益调整记录将自动清除！"
            } else {
                msg = "确定提交盘点结果吗?"
            }
            js.modal.confirm(msg, function (result) {
                js.post({
                    url: ctx + "material/checkPlan/updatePalStatus",
                    data: {
                        cpnId: $("#cpnId").val()
                    },
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            js.modal.success(result.msg);
                            location.reload();
                        } else {
                            js.modal.warning(result.msg);
                        }
                        js.modal.closeLoading();
                    }
                })
            })
        });

    });

</script>
</body>
</html>
